package cn.itcast.bos.web.action.take_delivery;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.base.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;

@Controller
@Scope("prototype")
@Namespace("/")
@ParentPackage("json-default")
public class OrderAction extends BaseAction<Order> {

	@Autowired
	private OrderService orderService;
	//输入订单号,回显订单数据
	@Action(value="waybill_orderData" ,results={@Result(name="success",type="json")})
	public String findOrderByOrderNum(){
		//创建map集合,封装数据
		Map<String,Object> map = new HashMap<>();
		//调用service层方法,处理数据,返回order对象
		Order order = orderService.findOrderByOrderNum(model.getOrderNum());
		System.out.println("返回的order对象为:"+order);
		//对返回的对象进行判断
		//存在,封装数据,压入栈顶
		if(order!=null){
			map.put("success", true);
			map.put("orderData", order);
		}else{
			map.put("success", false);
		}
		ActionContext.getContext().getValueStack().push(map);
		return SUCCESS;
	}
}
